package org.boulderfoodrescue.webapp.client.pickuptimes.timepicker;

import org.boulderfoodrescue.webapp.client.old.event.HasViewClosedHandlers;
import org.boulderfoodrescue.webapp.client.old.event.ViewClosedEvent;
import org.boulderfoodrescue.webapp.client.old.event.ViewClosedHandler;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.user.client.ui.DialogBox;

public class RepeatDialogBox extends DialogBox implements HasViewClosedHandlers<Boolean>{
	private EventBus bus = new SimpleEventBus();
	private RepeatDialogPanel panel;
	private RepeatDialogBox box;
	public RepeatDialogBox(PickupWindow window){
		panel = new RepeatDialogPanel(window);
		box = this;
		this.add(panel);
		this.setGlassEnabled(true);
		panel.addViewClosedHandler(new ViewClosedHandler<Boolean>(){
			@Override
			public void onViewClosed(ViewClosedEvent<Boolean> event) {
				ViewClosedEvent.fire(box, event.getCloseResult());
				hideDlg();
			}
		});
	}
	public void hideDlg(){
		hide();
	}

	@Override
	public void fireEvent(GwtEvent<?> event){
		bus.fireEvent(event);
	}

	@Override
	public HandlerRegistration addViewClosedHandler(ViewClosedHandler<Boolean> handler) {
		return bus.addHandler(ViewClosedEvent.getType(), handler);
	}
}
